#include <vector>
#include <iostream>


using namespace std;

int f[100005];
int g[100005];

int main()
{
    int n;
    cin >> n;
    cin >> f[0];
    for (int i = 1; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        if (tmp > f[i - 1])
        {
            f[i] = tmp;
            g[i] = f[i - 1];
        }
        else if (tmp > g[i - 1])
        {
            f[i] = f[i - 1];
            g[i] = tmp;
        }
        else
        {
            f[i] = f[i - 1];
            g[i] = g[i - 1];
        }
    }

    int q;
    cin >> q;
    while (q--)
    {
        int x;
        cin >> x;
        cout << g[x - 1] << endl;
    }
    return 0;
}